import requests
import base64

'''
#植物识别
'''

# encoding:utf-8
import requests
request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/plant"
access_token = ''

# client_id 为官网获取的AK， client_secret 为官网获取的SK
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=bnHtT9vLfhomex2Wf6yAOyV3&client_secret=zCNMZbVxDSrEU7QVR2Kvlces8oqyLcTp'
response = requests.get(host)
if response:
    print(response.json())
    jasonData = response.json()
    access_token=jasonData['access_token']
    print(access_token)


path='/Users/guasen/Projects/AI/实验二深度学习-花卉识别/花卉图像识别/origin_flower_photos/bee_balm/image_03029.jpg'
# 二进制方式打开图片文件
f = open(path, 'rb')
img = base64.b64encode(f.read())

params = {"image":img}
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
    print (response.json())
    
